import request from "@/utils/request";

export const login = (data) => {
  return request({
    // 请求地址
    url: "login",
    // 请求方法
    method: "POST",
    // body请求体传参
    data,
  });
};

export const getMenuListApi = () => {
  return request({
    url: "menus",
    method: "GET",
    // headers:{}
  });
};

//获取用户列表
export const getUserListApi = (params) => {
  return request({
    method: "get",
    url: "users",
    params,
  });
};

// 更改用户状态
export const changeUserInfoApi = (id, state) => {
  return request({
    method: "put",
    url: `users/${id}/state/${state}`,
  });
};

// 添加用户
export const addUserApi = (data) => {
  return request({
    method: "post",
    url: "users",
    data,
  });
};

//删除用户
export const delUserApi = (id) => {
  return request({
    method: "put",
    url: `users/${id}`,
  });
};

//获取用户信息
export const getUserIdApi = (id) => {
  return request({
    method: "GET",
    url: `users/${id}`,
  });
};

//修改用户信息
export const changeUserIdApi = (id, data) => {
  return request({
    method: "PUT",
    url: `users/${id}`,
    data,
  });
};

//删除用户信息
export const deleteUserApi = (id) => {
  return request({
    method: "DELETE",
    url: `users/${id}`,
  });
};

// 分配角色
export const distributeUser = (id, { rid }) => {
  return request({
    method: "put",
    url: `users/${id}/role`,
    data: {
      rid,
    },
  });
};
